package com.company.common.core.filter.xss;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 解决xss安全问题
 * 
 * @author
 *
 */
public class XssFilter implements Filter {
	private static final String HTTP_POST = "POST";

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		if (HTTP_POST.equals(((HttpServletRequest) request).getMethod())) {
			chain.doFilter(new XssHttpServletRequestWrapper((HttpServletRequest) request), response);
		} else {
			chain.doFilter(request, response);
		}
	}

	@Override
	public void destroy() {
	}
}
